package com.boot2551.test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Stu {
    public double sum(double a,double b){
        return  a+b;
    }

    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Stu s=new Stu();
        System.out.println(s.sum(10,10));
        //反射
        Class c=Stu.class;
        Stu s2=(Stu)c.newInstance();
        Method m=c.getDeclaredMethod("sum",double.class,double.class);
        //调用方法
        Object r=m.invoke(s,10,10);
        System.out.println(r);
    }
}
